package com.gxa.global.exception;

import com.gxa.common.R;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常的处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {

      @ExceptionHandler(IncorrectCredentialsException.class)
      @ResponseBody
      public R incorrectCredentialsException(){
          R r = new R();
          r.setCode(500);
          r.setMsg("账户或密码有误！");
          return r;
      }

     @ExceptionHandler(UnknownAccountException.class)
     @ResponseBody
     public R unknownAccountException(){
         R r = new R();
          r.setCode(500);
          r.setMsg("账户或密码有误！");
        return r;
     }

    @ExceptionHandler(UnauthorizedException.class)
    @ResponseBody
    public R unauthorizedException(){
        R r = new R();
        r.setCode(500);
        r.setMsg("此账户无权限访问");
        return r;
    }



}
